'''
''' IBAN Functions - IBANCreator.vb
'''
''' This program is free software; you can redistribute it and/or modify
''' it under the terms of the GNU General Public License as published by
''' the Free Software Foundation; either version 2 of the License, or
''' (at your option) any later version.
'''
''' This program is distributed in the hope that it will be useful,
''' but WITHOUT ANY WARRANTY; without even the implied warranty of
''' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
''' GNU General Public License for more details.
'''
''' You should have received a copy of the GNU General Public License
''' along with this program; if not, write to the Free Software
''' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'''

'''  -----------------------------------------------------------------------------
''' Project	 : IBANFuncsCore
''' Class	 : Core.IBANCreator
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' This class can synthesize an IBAN from the account elements.
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[Nick]	2/8/2007	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class IBANCreator

#Region "Public methods"

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Creates an IBAN from the account contents, after optionally validating them.
    ''' </summary>
    ''' <param name="account">An <see cref="IBANContents"/> instance with the account elements.</param>
    ''' <param name="ValidateContents">Specifies whether the account contents should be validated.</param>
    ''' <returns>String representation of the IBAN.</returns>
    ''' <remarks>
    ''' If <b>ValidateContents</b> is set to True, this method also calls the <see cref="M:IBANFuncs.Core.IBANAnalyzer.ValidateContents"/>
    ''' method. In addition to the exceptions thrown by this method, you should be prepared to catch any
    ''' exception raised by <see cref="M:IBANFuncs.Core.IBANAnalyzer.ValidateContents"/>.
    ''' </remarks>
    ''' <exception credf="XIBANInvalidCountryCodeException">Throw if the specified country code is invalid.</exception>
    ''' <history>
    ''' 	[Nick]	2/8/2007	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Shared Function CreateIBAN(ByVal account As IBANContents, _
                                      ByVal ValidateContents As Boolean) As String

        If ValidateContents = True Then
            'Check country validity
            Dim cntr As IBANCountryDef = IBANDefinitions.FindCountryByCode(account.CountryCode)
            If cntr Is Nothing Then Throw New XIBANInvalidCountryCodeException("Invalid country code " + account.CountryCode)

            'Validate the contents
            IBANAnalyzer.ValidateContents(account.BankCode, account.BranchCode, account.AccountNumber, cntr)
        End If

        Return IBANAlgorithm.CreateIBAN(account)

    End Function

#End Region

End Class
